package leetCode;

import java.util.List;

public class t206 {
    public static void main(String[] args) {
        ListNode node=new ListNode(1,new ListNode(2,new ListNode(6,new ListNode(3,new ListNode(4,new ListNode(5,new ListNode(6,null)))))));
        new Solution206().reverseList(node);
    }

}
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */

//class Solution206 {
//    public ListNode reverseList(ListNode head) {
//        ListNode dummyHead=new ListNode(0,null);
//        dummyHead.next=null;
//
//        while (head!=null){
//            ListNode oldNew=head;
//            head=head.next;
//            oldNew.next=dummyHead.next;
//            dummyHead.next=oldNew;
//
//        }
//        return dummyHead.next;
//    }
//}
class Solution206 {
    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode p = reverseList(head.next);
        head.next.next = head;
        head.next = null;
        return p;
    }
}

